package com.ltu.util.common;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import lombok.extern.slf4j.Slf4j;



/**
 * @Description:  配置文件操作工具
 * @author: 若尘  
 * @date 2018年9月17日 下午4:06:53
 * @version V1.0
 */
@Slf4j
public abstract class PropertiesUtils {
    


	private static Properties properties = null;
	public static String  filePath="third-party.properties";
	static {
		properties = loadProperty();
	}

	private static Properties loadProperty() {
		Properties p=null;
		try {
			p = PropertiesLoaderUtils.loadProperties(new ClassPathResource(filePath));
			
		} catch (IOException e) {

			e.printStackTrace();
		}
		
		return p;
	
	}

	public static String getValue(String key) {
		String value = properties.getProperty(key);

		return null == value ? "" : value;
	}
	public static void  setValue(String key ,String value)
	{
		properties.setProperty(key, value);
	}
	
	public  static void  saveProFile(){		
		try {
			FileOutputStream output = new FileOutputStream(ProjectPath.classPath+"/"+filePath);
			properties.store(output, "微信第三方平台的数据保存");
		    output.close();
		} catch (FileNotFoundException e) {

			e.printStackTrace();
		} catch (IOException e) {

			e.printStackTrace();
		}
	     
		}
	
}